package com.example.a22310.myapplication.ViewModel.Game;


import android.support.v4.app.FragmentActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.widget.Toast;

import com.example.a22310.myapplication.Adapter.MvvmAdapter;
import com.example.a22310.myapplication.Beans.Race;
import com.example.a22310.myapplication.Listener.ActivityLisenter;
import com.example.a22310.myapplication.Model.RaceModel;
import com.example.a22310.myapplication.R;

import java.util.List;

public class GameViewModel implements ActivityLisenter<Race> {
    private FragmentRecentRaceBinding binding;
    private FragmentActivity activity;
    public GameViewModel(FragmentActivity activity, FragmentRecentRaceBinding binding){
        this.activity = activity;
        this.binding = binding;
        binding.setGame(this);
        RaceModel RaceModel=new RaceModel();
        RaceModel.Racelist(GameViewModel.this);
    }

    @Override
    public void onSuccess(Race race) {
        if(race.getCode()!=404){
            List<Race.RacelistBean> racelistBeen =  race.getRacelist();
            binding.recyclerViewActivity.setLayoutManager(
                    new LinearLayoutManager(activity));
//            System.out.println("---->>>"+racelistBeen.get(0).getGame_name());
            MvvmAdapter adapter = new MvvmAdapter(activity, R.layout.cardview_game,
                    racelistBeen, BR.game);
            binding.recyclerViewActivity.setAdapter(adapter);

        }

    }

    @Override
    public void onFailure() {
        Toast.makeText(activity,"连接服务器失败", Toast.LENGTH_LONG).show();
    }
}
